package cn.joker.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SwaggerDocPrinter implements ApplicationListener<ApplicationReadyEvent> {

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        Environment env = event.getApplicationContext().getEnvironment();

        String port = env.getProperty("server.port", "8080");
        String contextPath = env.getProperty("server.servlet.context-path", "");
        String docUrl = "http://localhost:" + port + contextPath + "/doc.html";
        log.info("----------------------------------------------------------");
        log.info("Knife4j 接口文档地址: {}", docUrl);
        log.info("----------------------------------------------------------");
    }
}
